package com.example.myapplication

import android.content.Context
import com.example.myapplication.bean.User
import com.example.myapplication.data.LoginRequest
import com.example.myapplication.data.MailRepo
import com.example.myapplication.data.MailService
import com.ftw.commons.bean.Response
import com.ftw.commons.network.CallBack
import com.ftw.commons.network.HttpSubscriber
import com.ftw.commons.network.HttpUtils

/**
 * 描    述：我的
 * 作    者：wenjun
 * 时    间：2019/4/23  11:30 AM
 */
class LoginPresenter(view: LoginContract.View) : LoginContract.Presenter {

    private var mView: LoginContract.View = view

    override fun login(context: Context, account: String, pwd: String) {
        HttpUtils
            .toSubscribe(
                MailRepo.login(context, LoginRequest(account, pwd)),
                mView.onGet(),
                HttpSubscriber(
                    context, false, object : CallBack<Response<User>> {

                        override fun onError(code: Int, msg: String) {
                            mView.onError(code, msg)
                        }

                        override fun onSuccess(t: Response<User>) {
                            mView.loginComplete(t.data!!)

                        }

                    }
                )
            )
    }

}